package com.Main;
import java.io.*;
import java.net.*;

import com.protocols.ProtoOperations;

class TCPServer
{
   public static void main(String argv[]) throws Exception
      {
	   ServerSocket welcomeSocket = new ServerSocket(6789);
	   Socket connectionSocket = welcomeSocket.accept();
       System.out.println(connectionSocket.getRemoteSocketAddress());
       InputStream is = connectionSocket.getInputStream();       
       DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());

         while(true)
         {
            
            byte [] vvvv = new byte[300];
            int length=is.read(vvvv);
            byte [] input = ProtoOperations.extractByteArray(vvvv, 0, length);
            System.out.println("TCP Server: Received from client"+ProtoOperations.getHexString(input));
			outToClient.write(input);
         }
      }
}